<template>
	<view>
		<view class="login-img">
			<view class="owl-login">

			</view>
		</view>
		<view class="login-form">
			<form @submit="formSubmit">
				<view class="form-input ">
					<input type="text" maxlength="15" v-model="account" placeholder="皮皮号">
				</view>
				<view class="form-input">
					<input type="password" maxlength="20" placeholder="密码" v-model="password" @focus="passwordF_B"
						@blur="passwordF_B" />
				</view>

				<button :disabled="account == '' || password == '' ?true:false" type="primary"
					@click="submit()">登录</button>

			</form>
			<view style="padding-top: 10px;margin-left: 480upx; " class="text-blue"
				@click="navto('/pages/index/register')">新用户注册</view>
		</view>
	</view>
</template>

<script>
	var _self;
	var pages;
	import permision from "@/components/wa-permission/permission.js"
	export default {
		onLoad() {
			_self = this
		},
		data() {
			return {
				hideEyes: false,
				account: '',
				password: ''
			}
		},
		methods: {
			passwordF_B() {
				_self.hideEyes = !_self.hideEyes;
			},
			formSubmit(e) {
				console.log(e.detail.value);
			},
			submit() {

				var pushStatus = 0
				//安卓应用内提示更新
				switch (_self.$store.state.platform) {
					case 'android':
						break;
					case 'ios':
						if (permision.judgeIosPermission("push") === 2) {
							pushStatus = 0
						} else {
							pushStatus = 1
						}
						console.log('运行iOS上')
						break;
				}
				console.log("登录")
				uni.showLoading({
					title: '登录中'
				});

				_self.xhttp.request({
					url: "/user/login", //仅为示例，并非真实接口地址。
					method: "POST",
					data: {
						account: _self.account,
						password: _self.password,
						pushState: pushStatus,
						cid: plus.push.getClientInfo().clientid,
						platform: _self.$store.state.platform,
						appid: "com.ppgjx",
						version: _self.$store.state.version
					},
					header: {
						'Content-Type': 'application/json'
					}
				}).then(res => {
					if (res.data.code == 200) {
						_self.$store.state.user = res.data.data.userInfo
						_self.$store.state.user.token = res.data.data.token
						uni.setStorageSync('user', res.data.data.user);
						//创建socket连接
						var data = {
							uid: res.data.data.userInfo.userId,
							token: res.data.data.token
						}
						_self.$socket.dispatch("WEBSOCKET_INIT", data);
						uni.switchTab({
							url: '/pages/index/my'
						});
					}
					uni.hideLoading();
				}).catch(err => {
					uni.hideLoading();
				})

			}
		}
	}
</script>

<style>
	.login-form {
		margin: -9px 10px 0 10px;
		height: auto;
		background: #007AFF;
		border-radius: 10px;
		background-color: #EEEEEE;
		box-shadow: 0 2px 10px #9B9B9B;
		padding: 20px;
	}

	.form-input input {
		background: #ffffff;
		border-radius: 5px;
		height: 40px;
		margin: 20px 0;
		padding: 0 10px;
	}

	.login-img {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 108px;
		margin-top: 100upx;
	}

	.owl-login {
		width: 211px;
		height: 108px;
		background-image: url('');
		background-repeat: no-repeat;
		background-size: 100%;
	}
</style>
